package cn.tedu.dimanage.item.webapi.controller;


import cn.tedu.dimanage.common.web.JsonResult;
import cn.tedu.dimanage.item.service.IItemService;
import cn.tedu.dimanage.pojo.dto.ItemAddNewDTO;
import cn.tedu.dimanage.pojo.vo.ItemDetailVO;
import cn.tedu.dimanage.pojo.vo.ItemSimpleVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Classname: UserController
 * @Author: bromide
 * @CreateTime: 2022/6/10--13:07
 * @Version: V1.0
 * @Description:
 */
@RestController
@RequestMapping(value = "/item" , produces = "application/json;charset=utf-8")
public class ItemController {

    @Autowired
    private IItemService itemService;


    @RequestMapping("/add-new")
    public JsonResult<Void> addItem(ItemAddNewDTO itemAddNewDTO){
        itemService.addItem(itemAddNewDTO);
        return JsonResult.ok();
    }

    @RequestMapping("/deleteItemById")
    public JsonResult<Void> deleteItemById(Long id){
        itemService.deleteItemById(id);
        return JsonResult.ok();
    }

    @RequestMapping("/updateItem")
    public JsonResult<Void> updateItem(ItemDetailVO itemDetailVO){
        itemService.updateItem(itemDetailVO);
        return JsonResult.ok();
    }

    @RequestMapping("/details")
    public JsonResult<ItemDetailVO> getItemDetailsByName(String name){
        ItemDetailVO item = itemService.getItemDetailsByName(name);
        return JsonResult.ok(item);
    }

    @RequestMapping("/list")
    public JsonResult<List<ItemSimpleVO>> getListItems(String keyword){
        return JsonResult.ok(itemService.getListItems(keyword));
    }


}
